package com.probiz.estore.product.dao.impl;

import java.util.List;

import com.probiz.estore.common.model.product.ReviewVote;
import com.probiz.estore.core.dao.impl.HibernateGenericDaoImpl;
import com.probiz.estore.product.dao.ReviewVoteDao;

/**
 * Dao implementation for ReviewVote.
*/
public class ReviewVoteDaoImpl extends HibernateGenericDaoImpl<ReviewVote> implements ReviewVoteDao {
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.product.dao.ReviewVoteDao#isVoteAlready(java.lang.Integer, java.lang.Integer)
	 */
	public boolean isVoteAlready(Integer productReviewId, Integer customerId) {
		String hql="from ReviewVote rv where rv.productReview.productReviewId=? and rv.customer.appuserId=?";
		long count=countByHql(hql, new Object[]{productReviewId,customerId});
		return count>0;
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.product.dao.ReviewVoteDao#getByReviewIdAndCustomerId(java.lang.Integer, java.lang.Integer)
	 */
	public ReviewVote getByReviewIdAndCustomerId(Integer productReviewId, Integer customerId){
		List<ReviewVote> list= this.findByHql("from ReviewVote rv where rv.productReview.productReviewId=? and rv.customer.appuserId=?", productReviewId,customerId);
		if(list.size()>0){
			return list.get(0);
		}else{
			return null;
		}
	}

}
